
** Clearing Stata memory
capture log close
clear all
set more off, perm
set seed 1234

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// Figure O.1: Performance by Question Order ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

** Opening Phase 2 norm_scores dataset 
use "Work Data/Gender_Phase2_long.dta",clear

*********************************************************************************
**************** Main sample ****************************************************
*********************************************************************************

* 1) Only years before the affirmative action took place
drop if aa_year==1
drop if year==2000
tab year
keep if year<2003 // we only observe omissions for the years 2001-2002

*********************************************************************************
**************** Scores by order ************************************************
*********************************************************************************

forvalues i=1(1)12 {
gen score_item`i'=.
levelsof subject, local(levels) 
foreach s of local levels {
replace score_item`i'=`s'`i'_st2 if subject=="`s'"
}
tab subject, sum(score_item`i')
}

preserve
drop if subject=="port" | subject=="lang" 
tab year
keep subject year female priority score_item* inscri2
egen id_sub=group(inscri2 subject)
reshape long score_item, i(id_sub) j(order)
collapse (mean) score_item, by(order)
twoway (connected score_item order ), xlabel(1(1)12) xtitle("Question's order") ytitle("Female x Priority") ytitle("Average score")  ylabel(0(1)5)
graph export "Output/score_order_20012002.pdf", as(pdf) replace
restore

*********************************************************************************
**************** % perfect scores by order **************************************
*********************************************************************************

forvalues i=1(1)12 {
gen perfect_score_item`i'=. 
levelsof subject, local(levels) 
foreach s of local levels {
replace perfect_score_item`i'=1 if `s'`i'_st2==5 & subject=="`s'"
replace perfect_score_item`i'=0 if `s'`i'_st2<5 & subject=="`s'"
}
tab subject, sum(perfect_score_item`i')
}

preserve
drop if subject=="port" | subject=="lang" 
keep subject_long subject year female priority perfect_score_item* inscri2
tab year
egen id_sub=group(inscri2 subject)
reshape long perfect_score_item, i(id_sub) j(order)
collapse (mean) perfect_score_item, by(order)
twoway (connected perfect_score_item order ), xlabel(1(1)12) xtitle("Question's order") ytitle("Female x Priority") ytitle("% perfect scores")  ylabel(0(0.05)0.4) 
graph export "Output/perfect_score_order_20012002.pdf", as(pdf) replace
restore


*********************************************************************************
**************** % skipped questions by order ***********************************
*********************************************************************************

forvalues i=1(1)12 {
gen skipped_item`i'=.
levelsof subject, local(levels) 
foreach s of local levels {
replace skipped_item`i'=1 if missing_p2_`s'`i'==1 & subject=="`s'"
replace skipped_item`i'=0 if missing_p2_`s'`i'==0 & subject=="`s'"
}
tab subject, sum(skipped_item`i')
tab year, sum(skipped_item`i')
}


preserve
keep subject_long subject year female priority skipped_item* inscri2
drop if subject=="port" | subject=="lang" 
egen id_sub=group(inscri2 subject)
reshape long skipped_item, i(id_sub) j(order)
collapse (mean) skipped_item, by(order)
twoway (connected skipped_item order ), xlabel(1(1)12) xtitle("Question's order") ytitle("Female x Priority") ytitle("% skipped item")  ylabel(0(0.05)0.4)
graph export "Output/skipped_order.pdf", as(pdf) replace

restore

*********************************************************************************
**************** % answered and scored zero by order ****************************
*********************************************************************************

forvalues i=1(1)12 {
gen zero_score`i'=0 if year<=2002
levelsof subject, local(levels) 
foreach s of local levels {
replace zero_score`i'=1 if missing_p2_`s'`i'==0 & subject=="`s'" & `s'`i'_st2==0
}
tab subject, sum(zero_score`i')
tab year, sum(zero_score`i')
}

preserve
drop if subject=="port" | subject=="lang" 
keep subject_long subject year female priority zero_score* inscri2
egen id_sub=group(inscri2 subject)
reshape long zero_score, i(id_sub) j(order)
collapse (mean) zero_score, by(order)
twoway (connected zero_score order ), xlabel(1(1)12) xtitle("Question's order") ytitle("Female x Priority") ytitle("% zero score") ///
 ylabel(0(0.05)0.4)
graph export "Output/zeroscore_order.pdf", as(pdf) replace
restore
